import numpy as np
import pandas as pd

import matplotlib.pyplot as plt
import matplotlib as mpl

def drawContourMap(X, Y, Z, toPath, fileName, Z_MIN=-10, Z_MAX=1050, Z_STEP=1, LINE_STEP=10):
    '''
        XYZ画图参数  fileName保存成文件的文件名  toPath 保存文件的路径
    '''
    #将原始数据变成网格数据形式
    X, Y = np.meshgrid(X, Y)
    N = np.arange(Z_MIN, Z_MAX, Z_STEP)
    CS = plt.contourf(X,Y,Z,N,linewidth=2,cmap=mpl.cm.jet)
    plt.colorbar(CS)
    plt.savefig(toPath + fileName + '_without_line.jpg')
    plt.contour(X,Y,Z,LINE_STEP)
    plt.savefig(toPath + fileName + '.jpg')
    plt.close()
    # plt.show()

def read3DdataFromExcel(file):
    '''
    file 是excel文件的位置
    '''
    threeDFluDataFrame = pd.read_excel(file, header=None, index_col=None)
    ar = np.array(threeDFluDataFrame)
    X = (ar[0])[1:]  # 第一行中除去第一个元素
    Y = ((ar.T)[0])[1:]  # 第一列中除去第一个元素
    Z = ((ar[1:].T)[1:]).T  # 除去第一行和第一列
    print(np.max(Z))
    print(np.min(Z))
    return X, Y, Z

# X, Y, Z = read3DdataFromExcel('./target/510116005.xls')
# drawContourMap(X, Y, Z, './picture/', '510116005')

